package com.wc.算法提高课.C第三章_图论.有向图的强连通分量.学校网络;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/21 16:49
 * @description https://www.acwing.com/problem/content/369/
 */
public class Main {
    /**
     * 思路：强连通分量求的有几个强连通分量,然后拓扑求每个强连通分量的入度<p>
     * 入度为 0 就是需要提供的<p>
     * 第二问 max(入度为0的个数, 出度为0的个数)<p>
     * 特判只有一个点的情况, 0<p>
     * 证明, 假设|P|表示入度为0的点, |Q|表示出度为0的点<p>
     * |P| <= |Q|<p>
     * |P| = 1, 只需要所有的 q 向那个点连一条边即可, 答案是|Q|<p>
     * |P| > 1, 需要将一个Q中的点连接P中的一个点, 一共连掉 |P| - 1个, |Q| - (|P| - 1), 恢复到了|P| = 1的情况, 加起来还是|Q|
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110, M = N * N;
    static int[] h = new int[N], e = new int[M], ne = new int[M];
    static int[] stack = new int[N], din = new int[N], dout = new int[N];
    static int[] dfn = new int[N], low = new int[N], id = new int[N];
    static boolean[] instack = new boolean[N];
    static int idx = 1, scc_cnt = 0, timestamp = 0, top = 0;
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            int x;
            while ((x = sc.nextInt()) != 0) add(i, x);
        }
        for (int i = 1; i <= n; i++) {
            if (dfn[i] == 0) tarjan(i);
        }
        for (int u = 1; u <= n; u++) {
            for (int i = h[u]; i > 0; i = ne[i]) {
                int j = e[i];
                int a = id[u], b = id[j];
                if (a != b) {
                    dout[a]++;
                    din[b]++;
                }
            }
        }
        int a = 0, b = 0;
        for (int i = 1; i <= scc_cnt; i++) {
            if (din[i] == 0) a++;
            if (dout[i] == 0) b++;
        }
        out.println(a);
        if (scc_cnt == 1) out.println(0);
        else out.println(Math.max(a, b));
        out.flush();
    }

    static void add(int a, int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx++;
    }

    static void tarjan(int u) {
        dfn[u] = low[u] = ++timestamp;
        stack[++top] = u;
        instack[u] = true;
        for (int i = h[u]; i > 0; i = ne[i]) {
            int j = e[i];
            if (dfn[j] == 0) {
                tarjan(j);
                low[u] = Math.min(low[u], low[j]);
            } else if (instack[j]) low[u] = Math.min(low[u], dfn[j]);
        }
        if (dfn[u] == low[u]) {
            ++scc_cnt;
            int y;
            do {
                y = stack[top--];
                instack[y] = false;
                id[y] = scc_cnt;
            } while (y != u);
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
